package util;

import java.io.IOException;

public class Permutation {
	public String mem = new String();

	public void permute(int[] list) {
		this.permute(list, 0, list.length - 1);
		this.mem.trim();
	}

	public void permute(int[] list, int low, int high) {
		int i;
		if (low == high) {
			for (i = 0; i <= high; i++) {
				this.mem += list[i];
				this.mem += " ";
			}
		} else {
			for (i = low; i <= high; i++) {
				int temp = list[low];
				list[low] = list[i];
				list[i] = temp;
				permute(list, low + 1, high);
				temp = list[low];
				list[low] = list[i];
				list[i] = temp;
			}
		}
	}

	public static void main(String arf[]) throws IOException {
		Permutation demo = new Permutation();
		int[] suites = { 7, 81, 9 };
		demo.permute(suites);
		System.out.println(demo.mem);
	}
}
